/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package epibot.QualificaSites;

import epibot.BancoDeDados.ArmazenaDados.Fasta;
import epibot.GUI.FramePrincipal;
import epibot.WebRobots.RegrasSitesPreditores.RegraDosSites;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Rafael Tosta
 */
public class JPanelQualificaSites extends javax.swing.JPanel {

    private FramePrincipal fp;
    private ArrayList<Fasta> fastas = new ArrayList<Fasta>();
    private ArrayList<Fasta> fastas_busca = new ArrayList<Fasta>();
    private ArrayList<String[]> l_calibradores_original = new ArrayList<String[]>();
    private ArrayList<String[]> l_calibradores = new ArrayList<String[]>();
    private ArrayList<String> listaDeMotores = new ArrayList<String>();
    private ArrayList<String> todosMotores = new ArrayList<String>();
    private String nomeCalibragem = null;
    private String tamanho;
    private String alelo;
    private boolean ativa = true;
    private boolean ativaBimas = false;
    private boolean ativaIEDB = false;
    private boolean ativaNETMHC = false;
    private boolean ativaSYFPEITHI = false;

    private GerenciadorRobot_Calibragem gc;

    /**
     * Creates new form NewJPanelQualifica
     */
    public JPanelQualificaSites(FramePrincipal fp) {
        initComponents();
        this.fp = fp;

        setTamanhoAlelo();
    }

    public void iniciaPBar(int max) {
        jPBarQuery.setMaximum(max);
        jPBarQuery.setValue(0);
    }

    public void setValuePBar(int v) {
        jPBarQuery.setValue(v);
    }

    public JTextField getjTextProteina() {
        return jTextProteina;
    }

    public JTextField getjTextCalibradores() {
        return jTextCalibradores;
    }

    public void setjTextAreaQuery(String text) {
        this.jTextAreaQuery.append(text + "\n");
        jTextAreaQuery.setCaretPosition(jTextAreaQuery.getDocument().getLength());
    }

    public void setjTextAreaQuery_margem(String text) {
        this.jTextAreaQuery.append("     >>" + text + "\n");
        jTextAreaQuery.setCaretPosition(jTextAreaQuery.getDocument().getLength());
    }

    public void clearjTextAreaQuery() {
        this.jTextAreaQuery.setText("");
    }

    public void setjTextNotes(String text) {
        this.jTextNotes.append(text + "\n");
        jTextNotes.setCaretPosition(jTextNotes.getDocument().getLength());
    }

    public void clearjTextNotes() {
        this.jTextNotes.setText("");
    }

    public void setAvisoCalibration(String t) {
        this.avisoCalibration.setText(t);
    }

    public void setAvisoProtein(String t) {
        this.avisoProtein.setText(t);
    }

    public void setFastas(ArrayList<Fasta> fastas) {
        this.fastas = fastas;
    }

    public void setCalibradores(ArrayList<String[]> calibradores) {
        this.l_calibradores = calibradores;
        this.l_calibradores_original = calibradores;
    }

    public void setTamanhoAlelo() {
        setRegra();
        atualizaCalibradores();
        filtroFasta();

        aviso.setText(l_calibradores.size() + " calibrators\n and " + this.fastas_busca.size() + " proteins selected");
    }

    private void filtroFasta() {
        fastas_busca = new ArrayList<Fasta>();

        for (int i = 0; i < l_calibradores.size(); i++) {
            //String ep = l_calibradores.get(i)[0];
            String pro = l_calibradores.get(i)[1];

            for (int j = 0; j < this.fastas.size(); j++) {
                if (this.fastas.get(j).getCodProteina().equals(pro)) {
                    if (!isExistFiltro(pro)) {
                        fastas_busca.add(this.fastas.get(j));
                    }
                    j = this.fastas.size();
                }
            }
        }
    }

    private boolean isExistFiltro(String c) {
        for (int j = 0; j < this.fastas_busca.size(); j++) {
            if (this.fastas_busca.get(j).getCodProteina().equals(c)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Atualiza os l_calibradores filtrando pelas proteinas
     *
     */
    private void atualizaCalibradores() {
        ArrayList<String[]> listTemp = new ArrayList<String[]>();
        listTemp.addAll(this.l_calibradores_original);
        this.tamanho = (String) this.jComboBoxTamanho.getSelectedItem();
        l_calibradores = new ArrayList<String[]>();
        for (int i = 0; i < listTemp.size(); i++) {
            if (listTemp.get(i)[0].length() == Integer.parseInt(tamanho)) {
                l_calibradores.add(listTemp.get(i));
            }
        }
    }

    public final void setRegra() {
        this.tamanho = (String) this.jComboBoxTamanho.getSelectedItem();
        this.alelo = (String) this.jComboBoxAlelos.getSelectedItem();
        //   System.out.println(tamanho + " " + alelo);
        ArrayList<String> regra = RegraDosSites.getRegra(tamanho, alelo);
        this.bimas.setEnabled(false);
        this.bimas.setSelected(false);

        this.IEDB_consensus.setEnabled(false);
        this.IEDB_consensus.setSelected(false);

        this.NETMHC.setEnabled(false);
        this.NETMHC.setSelected(false);

        this.SYFPEITHI.setEnabled(false);
        this.SYFPEITHI.setSelected(false);

        todosMotores = new ArrayList<String>();
        selecionaTodosSites.setSelected(false);
        ativa = true;

        ativaBimas = false;
        this.listaDeMotores.remove(this.bimas.getText());

        ativaIEDB = false;
        this.listaDeMotores.remove(this.IEDB_consensus.getText());

        ativaNETMHC = false;
        this.todosMotores.remove(this.NETMHC.getText());

        ativaSYFPEITHI = false;
        this.listaDeMotores.remove(this.SYFPEITHI.getText());

        for (int i = 0; i < regra.size(); i++) {
            if (regra.get(i).equals("Bimas")) {
                this.bimas.setEnabled(true);
                this.todosMotores.add(this.bimas.getText());
            }
            if (regra.get(i).equals("IEDB_consensus")) {
                this.IEDB_consensus.setEnabled(true);
                this.todosMotores.add(this.IEDB_consensus.getText());
            }
            if (regra.get(i).equals("NETMHC")) {
                this.NETMHC.setEnabled(true);
                this.todosMotores.add(this.NETMHC.getText());
            }
            if (regra.get(i).equals("SYFPEITHI")) {
                this.SYFPEITHI.setEnabled(true);
                this.todosMotores.add(this.SYFPEITHI.getText());
            }
        }
    }

    /**
     * Inicia a lista de alelos
     *
     * @return
     */
    private String[] iniciaListaDeAlelos() {
        return RegraDosSites.getPaserAleloTodosOsSites();
    }

    /**
     * Inicia a lista de tamanhos
     *
     * @return
     */
    private String[] iniciaListaDeTamanhos() {
        return RegraDosSites.getPaserTamanhoTodosOsSites();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonSelectProntein = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextProteina = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaQuery = new javax.swing.JTextArea();
        jButtonSelectCalibradores = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextCalibradores = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nomeCal = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxTamanho = new javax.swing.JComboBox(this.iniciaListaDeTamanhos());
        jComboBoxAlelos = new javax.swing.JComboBox(this.iniciaListaDeAlelos());
        aviso = new javax.swing.JLabel();
        avisoProtein = new javax.swing.JLabel();
        avisoCalibration = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        selecionaTodosSites = new javax.swing.JCheckBox();
        bimas = new javax.swing.JCheckBox();
        IEDB_consensus = new javax.swing.JCheckBox();
        NETMHC = new javax.swing.JCheckBox();
        SYFPEITHI = new javax.swing.JCheckBox();
        jButtonRestore = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jButtonStart = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextNotes = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPBarQuery = new javax.swing.JProgressBar();

        setPreferredSize(new java.awt.Dimension(876, 590));

        jButtonSelectProntein.setText("Proteins file");
        jButtonSelectProntein.setPreferredSize(new java.awt.Dimension(170, 23));
        jButtonSelectProntein.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectPronteinActionPerformed(evt);
            }
        });

        jLabel1.setText("Path");

        jTextProteina.setEditable(false);
        jTextProteina.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N

        jTextAreaQuery.setEditable(false);
        jTextAreaQuery.setColumns(20);
        jTextAreaQuery.setRows(5);
        jTextAreaQuery.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Query"));
        jTextAreaQuery.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jScrollPane1.setViewportView(jTextAreaQuery);

        jButtonSelectCalibradores.setText("Calibration file");
        jButtonSelectCalibradores.setPreferredSize(new java.awt.Dimension(170, 23));
        jButtonSelectCalibradores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectCalibradoresActionPerformed(evt);
            }
        });

        jLabel2.setText("Path");

        jTextCalibradores.setEditable(false);
        jTextCalibradores.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N

        jLabel3.setText("Name");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Allele"));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setText("Type");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        jLabel5.setText("Size");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));

        jComboBoxTamanho.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTamanhoActionPerformed(evt);
            }
        });
        jPanel1.add(jComboBoxTamanho, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 20, 188, -1));

        jComboBoxAlelos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAlelosActionPerformed(evt);
            }
        });
        jPanel1.add(jComboBoxAlelos, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 60, 190, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Select the search engine"));

        selecionaTodosSites.setText("All");
        selecionaTodosSites.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selecionaTodosSitesActionPerformed(evt);
            }
        });

        bimas.setText("Bimas");
        bimas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                bimasItemStateChanged(evt);
            }
        });

        IEDB_consensus.setText("IEDB_consensus");
        IEDB_consensus.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                IEDB_consensusItemStateChanged(evt);
            }
        });

        NETMHC.setText("NETMHC");
        NETMHC.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                NETMHCItemStateChanged(evt);
            }
        });

        SYFPEITHI.setText("SYFPEITHI");
        SYFPEITHI.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                SYFPEITHIItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(selecionaTodosSites, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bimas)
                            .addComponent(IEDB_consensus))
                        .addGap(53, 53, 53)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(NETMHC)
                            .addComponent(SYFPEITHI))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(NETMHC)
                        .addGap(7, 7, 7)
                        .addComponent(SYFPEITHI))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(selecionaTodosSites)
                        .addGap(7, 7, 7)
                        .addComponent(bimas)
                        .addGap(7, 7, 7)
                        .addComponent(IEDB_consensus)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonRestore.setText("Restore configurations");
        jButtonRestore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRestoreActionPerformed(evt);
            }
        });

        jButtonCancel.setText("Cancel");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        jButtonStart.setText("Start");
        jButtonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartActionPerformed(evt);
            }
        });

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("Notes"));

        jTextNotes.setEditable(false);
        jTextNotes.setColumns(20);
        jTextNotes.setRows(5);
        jTextNotes.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jScrollPane2.setViewportView(jTextNotes);

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 48)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(204, 204, 204));
        jLabel6.setText("EPIBOT");

        jLabel7.setForeground(new java.awt.Color(153, 153, 153));
        jLabel7.setText("Discovery Epitope");

        jPBarQuery.setStringPainted(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextProteina, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextCalibradores, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(nomeCal, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonSelectCalibradores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonSelectProntein, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(avisoCalibration, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(aviso, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(jButtonRestore, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jSeparator2))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(avisoProtein, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(50, 50, 50)))
                        .addGap(28, 28, 28))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(91, 91, 91))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPBarQuery, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonSelectCalibradores, jButtonSelectProntein});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextCalibradores, nomeCal});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonCancel, jButtonStart});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonSelectProntein, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jTextProteina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addComponent(avisoProtein, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonSelectCalibradores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jTextCalibradores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nomeCal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(avisoCalibration, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(aviso, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPBarQuery, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addGap(38, 38, 38))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonRestore)
                    .addComponent(jButtonCancel)
                    .addComponent(jButtonStart))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Evento para importar uma proteína
     *
     * @param evt
     */
    private void jButtonSelectPronteinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectPronteinActionPerformed
        ImportProteina i = new ImportProteina(this);
        i.start();
        // setTamanhoAlelo();
    }//GEN-LAST:event_jButtonSelectPronteinActionPerformed

    private void jButtonSelectCalibradoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectCalibradoresActionPerformed
        ImportCalibradores i = new ImportCalibradores(this);
        i.start();
        //setTamanhoAlelo();
    }//GEN-LAST:event_jButtonSelectCalibradoresActionPerformed

    private void jComboBoxTamanhoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTamanhoActionPerformed
        setTamanhoAlelo();
    }//GEN-LAST:event_jComboBoxTamanhoActionPerformed

    private void jComboBoxAlelosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAlelosActionPerformed
        setTamanhoAlelo();
    }//GEN-LAST:event_jComboBoxAlelosActionPerformed

    private void selecionaTodosSitesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selecionaTodosSitesActionPerformed
        if (ativa == true) {
            ativa = false;
        } else {
            ativa = true;
        }
        for (int i = 0; i < this.todosMotores.size(); i++) {

            if (this.todosMotores.get(i).equals("Bimas")) {
                this.bimas.setEnabled(ativa);
            }
            if (this.todosMotores.get(i).equals("IEDB_consensus")) {
                this.IEDB_consensus.setEnabled(ativa);
            }
            if (this.todosMotores.get(i).equals("NETMHC")) {
                this.NETMHC.setEnabled(ativa);
            }
            if (this.todosMotores.get(i).equals("SYFPEITHI")) {
                this.SYFPEITHI.setEnabled(ativa);
            }
        }
    }//GEN-LAST:event_selecionaTodosSitesActionPerformed

    private void bimasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_bimasItemStateChanged
        if (ativaBimas == true) {
            ativaBimas = false;
            this.listaDeMotores.remove(this.bimas.getText());
        } else {
            ativaBimas = true;
            this.listaDeMotores.add(this.bimas.getText());
        }
    }//GEN-LAST:event_bimasItemStateChanged

    private void IEDB_consensusItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_IEDB_consensusItemStateChanged
        if (ativaIEDB == true) {
            ativaIEDB = false;
            this.listaDeMotores.remove(this.IEDB_consensus.getText());
        } else {
            ativaIEDB = true;
            this.listaDeMotores.add(this.IEDB_consensus.getText());
        }
    }//GEN-LAST:event_IEDB_consensusItemStateChanged

    private void NETMHCItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_NETMHCItemStateChanged
        if (ativaNETMHC == true) {
            ativaNETMHC = false;
            this.listaDeMotores.remove(this.NETMHC.getText());
        } else {
            ativaNETMHC = true;
            this.listaDeMotores.add(this.NETMHC.getText());
        }
    }//GEN-LAST:event_NETMHCItemStateChanged

    private void SYFPEITHIItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_SYFPEITHIItemStateChanged
        if (ativaSYFPEITHI == true) {
            ativaSYFPEITHI = false;
            this.listaDeMotores.remove(this.SYFPEITHI.getText());
        } else {
            ativaSYFPEITHI = true;
            this.listaDeMotores.add(this.SYFPEITHI.getText());
        }
    }//GEN-LAST:event_SYFPEITHIItemStateChanged

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        fp.atualizaFrame();
        if (gc != null) {
            gc.stop();
        }
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
        //verifica se tudo foi preenchido

        if (this.fastas.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Insert protein file!");
            return;
        }

        if (this.l_calibradores_original.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Insert calibration file!");
            return;
        }

        //verificar o nome do calibrador        
        if (nomeCal.getText().length() != 0) {
            int o = 0, j;
            boolean flag = false;
            String nome = "";
            for (j = 0; j < nomeCal.getText().length(); j++) {
                if (nomeCal.getText().charAt(j) == ' ') {
                    o++;
                    if (flag) {
                        nome = nome + nomeCal.getText().charAt(j);
                    }
                } else {
                    flag = true;
                    nome = nome + nomeCal.getText().charAt(j);
                }
            }
            if (o != j) {
                this.nomeCalibragem = nome;
            } else {
                JOptionPane.showMessageDialog(this, "Insert calibration name!");
                return;
            }
        } else {
            JOptionPane.showMessageDialog(this, "Insert calibration name!");
            return;
        }

        if (this.l_calibradores.isEmpty()) {
            JOptionPane.showMessageDialog(this, "No calibration for search!");
            return;
        }
        if (this.fastas_busca.isEmpty()) {
            JOptionPane.showMessageDialog(this, "No protein for search!");
            return;
        }

        ArrayList<String> temp;
        if (ativa == false) {
            temp = this.todosMotores;
        } else {
            temp = this.listaDeMotores;
        }

        if (ativaBimas || ativaSYFPEITHI || ativaIEDB || ativaNETMHC || !ativa) {

            gc = new GerenciadorRobot_Calibragem(this, temp, fastas_busca, l_calibradores, tamanho, alelo, nomeCalibragem);
            gc.start();

        } else {
            JOptionPane.showMessageDialog(this, "Select the search engine!");
        }

    }//GEN-LAST:event_jButtonStartActionPerformed

    private void jButtonRestoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRestoreActionPerformed
        fastas = new ArrayList<Fasta>();
        fastas_busca = new ArrayList<Fasta>();
        l_calibradores_original = new ArrayList<String[]>();
        l_calibradores = new ArrayList<String[]>();
        listaDeMotores = new ArrayList<String>();
        todosMotores = new ArrayList<String>();
        nomeCalibragem = null;
        tamanho = null;
        alelo = null;
        ativa = true;
        ativaBimas = false;
        ativaIEDB = false;
        ativaNETMHC = false;
        ativaSYFPEITHI = false;

        nomeCal.setText("");
        getjTextCalibradores().setText("");
        getjTextProteina().setText("");
        setAvisoCalibration("");
        setAvisoProtein("");
        clearjTextAreaQuery();
        clearjTextNotes();
        setTamanhoAlelo();
    }//GEN-LAST:event_jButtonRestoreActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox IEDB_consensus;
    private javax.swing.JCheckBox NETMHC;
    private javax.swing.JCheckBox SYFPEITHI;
    private javax.swing.JLabel aviso;
    private javax.swing.JLabel avisoCalibration;
    private javax.swing.JLabel avisoProtein;
    private javax.swing.JCheckBox bimas;
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonRestore;
    private javax.swing.JButton jButtonSelectCalibradores;
    private javax.swing.JButton jButtonSelectProntein;
    private javax.swing.JButton jButtonStart;
    private javax.swing.JComboBox jComboBoxAlelos;
    private javax.swing.JComboBox jComboBoxTamanho;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JProgressBar jPBarQuery;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextArea jTextAreaQuery;
    private javax.swing.JTextField jTextCalibradores;
    private javax.swing.JTextArea jTextNotes;
    private javax.swing.JTextField jTextProteina;
    private javax.swing.JTextField nomeCal;
    private javax.swing.JCheckBox selecionaTodosSites;
    // End of variables declaration//GEN-END:variables
}
